// 引入业务接口命名空间
using Business.Interfaces.IOCTEst;
// 引入业务服务命名空间
using Business.Services.IOCTEst;
// 引入JWT认证相关命名空间
using Microsoft.AspNetCore.Authentication.JwtBearer;
// 引入授权相关命名空间
using Microsoft.AspNetCore.Authorization;
// 引入配置相关命名空间
using Microsoft.Extensions.Configuration;

// 定义MinimalApi命名空间
namespace MinimalApi
{
    // 定义静态类OrderMinimalApiExt，用于扩展WebApplication功能
    public static class OrderMinimalApiExt
    {
        // 定义扩展方法OrderExtension，用于注册订单相关的API端点
        public static void OrderExtension(this WebApplication app)
        {
            //反射引用Business.Interfaces中的IMicophone类
            //var type = typeof(Business.Interfaces.IOCTEst.IMicrophone);
            
            // 注册查询订单的GET接口
            app.MapGet("/QueryOrder", (int Id,HttpContext context, IConfiguration configuration, IMicrophone microphone,IPhone phone) =>
            {
                //参数---注入
                //上下文---注入
                //Service服务
                var query = context.Request.Query;
                var microphone1 = microphone;
                var phone1 = phone;
                var configuration1 = configuration;//配置文件
                return new
                {
                    Id = 123,
                    Name = "张三",
                    Age = 35
                };
            })
            .WithName("QueryOrder")
            .WithTags("Order")
            .RequireAuthorization()
            .WithMetadata(new AuthorizeAttribute { AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme });  

            // 注册添加订单的POST接口
            app.MapPost("/AddOrder", () =>
            {
                return new
                {
                    Success = true,
                    Message = "添加成功"
                };
            })
            .WithName("AddOrder")
            .WithTags("Order");  

            // 注册更新订单的PUT接口
            app.MapPut("/UpdateOrder", () =>
            {
                return new
                {
                    Success = true,
                    Message = "修改成功"
                };
            })
            .WithName("UpdateOrder")
            .WithTags("Order");  

            // 注册删除订单的DELETE接口
            app.MapDelete("/DeleteOrder", () =>
            {
                return new
                {
                    Success = true,
                    Message = "删除成功"
                };
            })
            .WithName("DeleteOrder")
            .WithTags("Order");  
        }
    }
}
